/**
 * Huisou.com Inc.
 * Copyright (c) 2011-2012 All Rights Reserved.
 */

package com.chenzehe.zdmya.service;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.chenzehe.java.core.orm.Page;
import com.chenzehe.java.core.orm.PageRequest;
import com.chenzehe.zdmya.dao.BaoliaoDao;
import com.chenzehe.zdmya.domain.Baoliao;
import static com.chenzehe.java.core.Status.STATUS_NORMAL;

/**
 * @description
 * 
 * @author chenzehe
 * @email hljuczh@163.com
 * @create 2012-8-14 下午09:00:35
 */
@Service
@Transactional
public class BaoliaoService extends BaseService implements IBaoliaoService {

	@Resource
	BaoliaoDao baoliaoDao;

	@Override
	public int saveBaoliao(Baoliao baoliao) {
		baoliaoDao.save(baoliao);
		return 1;
	}

	@Override
	public Page<Baoliao> queryBaoliaoByUser(PageRequest pageRequest, int userId) {
		String hql = "FROM Baoliao x WHERE userId=?";
		return baoliaoDao.findPage(pageRequest, hql, userId);
	}

	@Override
	public Page<Baoliao> queryBaoliaoByUserAndStatus(PageRequest pageRequest,
			int userId, int status) {
		String hql = "FROM Baoliao x WHERE userId=? AND status=?";
		return baoliaoDao.findPage(pageRequest, hql, userId, status);
	}

	@Override
	public Long queryBaoliaoNumByUser(int userId) {
		String sql = "SELECT COUNT(*) FROM tbl_baoliao WHERE user_id=? AND status=?";
		return jdbcTemplate.queryForLong(sql, userId, STATUS_NORMAL.getState());
	}

}
